//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.eResearch.Ontology.Mapping.Mappers
{
    using System;
    using System.Collections.Generic;
    using System.Workflow.Runtime.Tracking;
    using Microsoft.Research.eResearch.Ontology.Lookup;

    /// <summary>
    /// Implementation for TrackingParameter mapping mediator.
    /// </summary>
    [OntologicalTypeMapper(typeof(TrackingParameters))]
    public class TrackingParametersMapper : IOntologicalTypeMapper
    {
        /// <summary>
        /// Creates list of all the concept value pairs for the given object using lookup table.
        /// </summary>
        /// <param name="table">Instance of the lookup table.</param>
        /// <param name="input">Instance of the input object.</param>
        /// <returns>List of concept value pairs.</returns>
        public List<List<ConceptValuePair>> MapConceptValuePairs(IOntologyLookupTable table, object input)
        {
            List<List<ConceptValuePair>> messages = new List<List<ConceptValuePair>>();

            TrackingParameters parameters = input as TrackingParameters;
            if (input != null)
            {
                List<ConceptValuePair> message = new List<ConceptValuePair>();

                message.Add(new ConceptValuePair(
                    table.MapPropertyToConcept(typeof(TrackingParameters), "CallerContextGuid"),
                    parameters.CallerContextGuid.ToString()));
                message.Add(new ConceptValuePair(
                    table.MapPropertyToConcept(typeof(TrackingParameters), "CallerInstanceId"),
                    parameters.CallerInstanceId.ToString()));
                message.Add(new ConceptValuePair(
                    table.MapPropertyToConcept(typeof(TrackingParameters), "CallerParentContextGuid"),
                    parameters.CallerParentContextGuid.ToString()));
                message.Add(new ConceptValuePair(
                    table.MapPropertyToConcept(typeof(TrackingParameters), "ContextGuid"),
                    parameters.ContextGuid.ToString()));
                message.Add(new ConceptValuePair(
                    table.MapPropertyToConcept(typeof(TrackingParameters), "InstanceId"),
                    parameters.InstanceId.ToString()));
                message.Add(new ConceptValuePair(
                    table.MapPropertyToConcept(typeof(TrackingParameters), "WorkflowType"),
                    parameters.WorkflowType.AssemblyQualifiedName));

                // Note: parameters.CallStack and parameters.RootActivity aren't used
                messages.Add(message);
            }
            else
            {
                // Something is wrong with the OntologicalTypeMapperManager
                throw new NotSupportedException("There is a problem with the OntologicalTypeMapperManager.");
            }

            return messages;
        }
    }
}
